

if __name__ == '__main__':
    with open("main.basm.o", 'rb') as f:
        fileData = f.read()
    objSize = len(fileData)

    if objSize % 16 != 0:
        fileData += bytes([255] * (16-objSize % 16))

    objSize = len(fileData)

    with open("bs_firm_data.c", 'w', encoding="utf-8") as f:
        f.write("#include <stdint.h>\n")
        f.write(f"uint32_t bs_main_length = {objSize};\n\n")
        f.write(f"uint8_t const bs_main_data[{objSize}] = " + '{\n')
        for i in range(0, objSize, 16):
            for j in range(16):
                f.write("0x{:02X},".format(fileData[i+j]))
            f.write("\n")
        f.write("};\n")
